﻿function cutstr(text, start, end) {
    var s = text.indexOf(start)
    if (s > -1) {
        var text2 = text.substr(s + start.length);
        var s2 = text2.indexOf(end);
        if (s2 > -1) {
            result = text2.substr(0, s2);
        } else
            result = '';
    } else
        result = '';
    return result;
}

function onlyNum(obj) {
    obj.value = obj.value.replace(/\D/g, '')
}

function keyDownOnlyNum() {
    //alert(event.keyCode);
    if (!(event.keyCode == 46) && !(event.keyCode == 8) && !(event.keyCode == 37) && !(event.keyCode == 39))
        if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)))
            event.returnValue = false;
}

function keyDownMoney() {
    if (!(event.keyCode == 46) && !(event.keyCode == 8) && !(event.keyCode == 37) && !(event.keyCode == 39) && !(event.keyCode == 110) && !(event.keyCode == 190))
        if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)))
            event.returnValue = false;
}
function Money(obj) {
    obj.value = obj.value.replace(/\D\./g, '')
    obj.value = obj.value.replace(/^\./g, '');
    obj.value = obj.value.replace(".", "$#quot;").replace(/\./g, "").replace("$#quot;", ".");
}

function MessageDialog(msg) {

    BUI.Message.Show({
        title: '提示',
        msg: msg,
        buttons: [
          {
              text: '确定',
              elCls: 'button button-primary',
              handler: function () {
                  if (msg != undefined) {
                      if (msg.indexOf('成功') >= 0)
                          BUI.Message.Alert(msg, 'success');
                      else
                          BUI.Message.Alert(msg, 'error');
                  }
                  else {
                      var substr = cutstr(msg, "BUI.Message.Alert", "function");
                      substr = substr.replace("'", "").replace("'", "").replace("(", "").replace(",", "");
                      if (substr == "")
                          BUI.Message.Alert("操作失败，请联系技术人员", 'warning');
                      else {
                          if (substr.indexOf("请重新登录") > 0) {
                              BUI.Message.Alert(substr, function () {
                                  top.location.href = '@Url.Action("Login","User")';
                              }, 'warning');
                          }
                          else {
                              BUI.Message.Alert(substr, 'warning');
                          }
                      }
                  }

                  this.close();
              }
          }
        ]
    });
}

//验证电话号码
function checkPhone(str) {
    var re = /^0\d{2,3}-?\d{7,8}$/;
    if (re.test(str)) {
        return true;
    } else {
        return false;
    }
}

//验证手机号码
function checkMobile(str) {
    var re = /^1\d{10}$/
    if (re.test(str)) {
        return true;
    } else {
        return false;
    }
}

//bui 添加新标签页
function newTab(url, title) {
    if (url.indexOf('&amp;') > 0) {
        url = url.replace(/&amp;/g, '&');
    }
    var config = {
        title: title,
        href: url
    };
    top.module.tab.addTab(config);
}